package com.parenting.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.parenting.entities.ActivityDO;
import com.parenting.entities.CommodityDO;
import com.parenting.model.UserDTO;
import com.parenting.oauth2.config.AuthUtil;
import com.parenting.request.*;
import com.parenting.response.*;
import com.parenting.service.ActivityService;
import com.parenting.service.CommodityService;
import com.parenting.service.CouponService;
import com.parenting.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 活动 前端控制器
 * </p>
 *
 * @author 烟台业达-王世玺
 * @since 2021-08-27
 */
@Api(tags = "活动管理", description = "活动管理，新增、列表")
@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /***
     * 裂变零元购 新增
     */
    @ApiOperation(" 裂变零元购 新增")
    @PostMapping("addFission")
    public Result addFissionActivity(@RequestBody @Validated AddActivityFissionRequest fissionRequest){

        UserDTO userInfo = AuthUtil.getUserInfo();
        activityService.addFissionActivity(fissionRequest,  userInfo);
        return  Result.buildSuccess();
    }
    /***
     * 免费体验 新增
     */
    @ApiOperation("免费体验 新增")
    @PostMapping("addFree")
    public Result  addFreeActivity(@RequestBody @Validated  AddActivityFreeRequest freeRequest){
        activityService.addFreeActivity(freeRequest,AuthUtil.getUserInfo());
        return  Result.buildSuccess();
    }


    /***
     * 代金券活动新增
     */
    @ApiOperation("代金券活动新增")
    @PostMapping("addVoucher")
    public Result  addVoucherActivity(@RequestBody @Validated  AddActivityVoucherRequest voucherRequest){
        activityService.addVoucherActivity(voucherRequest,AuthUtil.getUserInfo());
        return  Result.buildSuccess();
    }

    /****
     * 添加普通拼
     */
    @ApiOperation("添加普通拼")
    @PostMapping("addCollage")
    public Result  addCollageActivity(@RequestBody @Validated  AddActivityCollageRequest request){
        activityService.addCollageActivity(request,AuthUtil.getUserInfo());
        return  Result.buildSuccess();
    }


    /***
     * 裂变零元购 新增
     */
    @ApiOperation("查询裂变零元购详情")
    @ApiImplicitParam(name = "activityId", value = "活动ID", required = true)
    @GetMapping("fission/{activityId}")
    public Result<List<FissionResponse>> getFissionActivity(@PathVariable("activityId") String activityId){
        List<FissionResponse> fissionActivity = activityService.getFissionActivity(activityId);
        return  Result.buildSuccess(fissionActivity);
    }
    /***
     * 免费体验 新增
     */
    @ApiOperation("查询免费体验详情")
    @ApiImplicitParam(name = "activityId", value = "活动ID", required = true)
    @GetMapping("free/{activityId}")
    public Result<List<FreeResponse>> getFreeActivity(@PathVariable("activityId")String activityId){
        List<FreeResponse> freeActivity = activityService.getFreeActivity(activityId);
        return  Result.buildSuccess(freeActivity);
    }

    /***
     * 代金券活动新增
     */
    @ApiOperation("查询代金券活动详情")
    @ApiImplicitParam(name = "activityId", value = "活动ID", required = true)
    @GetMapping("voucher/{activityId}")
    public Result<List<VoucherResponse>> getVoucherActivity(@PathVariable("activityId")String activityId){
        List<VoucherResponse> voucherActivity = activityService.getVoucherActivity(activityId);
        return  Result.buildSuccess(voucherActivity);
    }

    /****
     * 添加普通拼
     */
    @ApiOperation("查询普通拼详情")
    @ApiImplicitParam(name = "activityId", value = "活动ID", required = true)
    @GetMapping("collage/{activityId}")
    public Result<List<CollageResponse>> getCollageActivity(@PathVariable("activityId")String activityId){

        return  Result.buildSuccess(activityService.getCollageActivity(activityId));
    }
    /***
     * 活动分页列表
     * @param activityBaseRequest
     * @return
     */
    @ApiOperation("活动分页列表")
    @PostMapping("page")
    public Result<IPage<ActivityDO>> getActivityPageBy(@RequestBody ActivityBaseRequest activityBaseRequest){
        return  Result.buildSuccess(activityService.getActivityPageBy(activityBaseRequest,AuthUtil.getUserInfo().getShopId()));
    }


    @Autowired
    private CouponService couponService;

    @ApiOperation("获得优惠券下拉")
    @GetMapping("drop/{type}")
    public  Result< List<CouponDropDown>>  getCouponDropDown(@PathVariable("type") String type){
        List<CouponDropDown> couponDropDown = couponService.getCouponDropDown(AuthUtil.getUserInfo().getShopId(), type);
        return  Result.buildSuccess(couponDropDown);
    }


    @Autowired
    private CommodityService commodityService;

    @ApiOperation("获得商品下拉")
    @GetMapping("/commodity/drop/")
    public Result<List<CommodityDO>> getCommodityByCouponId(){
        List<CommodityDO> commodityDropDown = commodityService.getCommodityDropDown(AuthUtil.getUserInfo().getShopId());
        return  Result.buildSuccess(commodityDropDown);
    }


    @ApiOperation("活动关闭")
    @ApiImplicitParam(name = "activityIds", value = "活动ID的集合", required = true)
    @PostMapping("/close/")
    public  Result closeActivity(@RequestBody List<String> activityIds){
        activityService.closeActivity(activityIds);
        return  Result.buildSuccess();
    }
}

